require("../css/login.less")

const CaptchaMini = require("../lib/captcha-mini.js")

let captcha1 = new CaptchaMini();
document.ready(function(){

    let code=""
    captcha1.draw(document.querySelector('#captcha1'), r => {
        // console.log(r, '验证码1');
        code=r
    });

    let phoneIp=document.querySelector("#phoneIp")
    let vertion=document.querySelector("#vertion")
    let mypassword1=document.querySelector("#mypassword1")
    let mypassword2=document.querySelector("#mypassword2")
    let btn=document.querySelector("#btn")
    let tips=document.querySelector("#tips")

    btn.addEventListener("click",function(){
        let phone=phoneIp.value
        let ver=vertion.value
        let password1=mypassword1.value
        let password2=mypassword2.value
        if(!window.$utils.isPhone(phone)){
            tips.textContent="请输入正确的手机号码"
        }else if(ver.toLowerCase()!=code.toLowerCase()){
            tips.textContent="验证码输入有误"
        }else if(!window.$utils.isPassword(password1)){
            tips.textContent="请输入6-12位的字母数字下划线"
        }else if(password1!=password2){
            tips.textContent="两次密码不一致"
        }else{
            tips.textContent=""

            axios.post("http://139.9.177.51:8099/users/add",
            {
                "account": phone,
                "password": password1
            }
            ).then(function(res){
                let ret=res.data
                if(ret.status===0){
                    // alert("注册成功")
                    window.$utils.toast("duigou","注册成功")
                    window.setTimeout(function(){
                        window.location.href="./register.html"
                    },3000)
                    
                }else if(ret.status===1){
                    // alert("注册失败")
                    window.$utils.toast("cuowu","注册失败")
                }
            }).catch(function(err){

            })
        }
    })
})